﻿using MDT.LifeSewagePlatform.Entity;
using MDT.LifeSewagePlatform.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;
using MDT.LifeSewagePlatform.Conmmon;

/*********************************************************
 * 命名空间 MDT.LifeSewagePlatform.Repository
 * 接口名称 RuleCompanyRepository
 * 开发人员：-nhy
 * 创建时间：2022/3/31 16:51:59
 * 描述说明：
 * 更改历史：
 * 
 * *******************************************************/
namespace MDT.LifeSewagePlatform.Repository
{
    public class RuleCompanyRepository:HandleBaseRepository<RuleCompanyEntity>,IRuleCompanyRepository
    {
        public RuleCompanyRepository()
        {

        }

        public IQueryable<RuleCompanyView> GetRuleCompany(Expression<Func<RuleCompanyView,bool>> expression)
        {


            var query = from ruleCompany in _dbContext.RuleCompany.AsNoTracking()
                        join alaramType in _dbContext.Details.AsNoTracking().Where(a => a.MainID.Equals((int)eDictionary.alaramType)) on ruleCompany.AlaramType equals alaramType.RowID
                        join comparePattern in _dbContext.Details.AsNoTracking().Where(a => a.MainID.Equals((int)eDictionary.comparePattern)) on ruleCompany.AlaramType equals comparePattern.RowID
                        join company in _dbContext.Company.AsNoTracking() on ruleCompany.CompanyID equals company.ID
                        select new RuleCompanyView()
                        {
                            AlaramType=ruleCompany.AlaramType,
                            AlaramTypeName=alaramType.RowName,
                            CompanyID=ruleCompany.CompanyID,
                            ComparePattern=ruleCompany.ComparePattern,
                            Id=ruleCompany.ID,
                            Standard=ruleCompany.Standard,
                            DescriptionInfo=ruleCompany.DescriptionInfo,
                            ComparePatternName=comparePattern.RowName,
                            CompanyName=company.CompanyName,
                            Enable=ruleCompany.Enable,
                            IsDelete=ruleCompany.IsDelete,
                            
                        };
            return query.Where(expression);
        }
    }
}
